home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg2.cab / table_cells.xsl < prev    next >
Extensible Markup Language  |  2005-09-10  |  13KB  |  278 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.  
  4.     OpenOffice.org - a multi-platform office productivity suite
  5.  
  6.     $RCSfile: table_cells.xsl,v $
  7.  
  8.     $Revision: 1.5 $
  9.  
  10.     last change: $Author: rt $ $Date: 2005/09/08 22:02:43 $
  11.  
  12.     The Contents of this file are made available subject to
  13.     the terms of GNU Lesser General Public License Version 2.1.
  14.  
  15.  
  16.       GNU Lesser General Public License Version 2.1
  17.       =============================================
  18.       Copyright 2005 by Sun Microsystems, Inc.
  19.       901 San Antonio Road, Palo Alto, CA 94303, USA
  20.  
  21.       This library is free software; you can redistribute it and/or
  22.       modify it under the terms of the GNU Lesser General Public
  23.       License version 2.1, as published by the Free Software Foundation.
  24.  
  25.       This library is distributed in the hope that it will be useful,
  26.       but WITHOUT ANY WARRANTY; without even the implied warranty of
  27.       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  28.       Lesser General Public License for more details.
  29.  
  30.       You should have received a copy of the GNU Lesser General Public
  31.       License along with this library; if not, write to the Free Software
  32.       Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33.       MA  02111-1307  USA
  34.  
  35. -->
  36. <!--
  37.     For further documentation and updates visit http://xml.openoffice.org/sx2ml
  38. -->
  39. <xsl:stylesheet version="1.0"
  40.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  41.     xmlns:office="http://openoffice.org/2000/office"
  42.     xmlns:style="http://openoffice.org/2000/style"
  43.     xmlns:text="http://openoffice.org/2000/text"
  44.     xmlns:table="http://openoffice.org/2000/table"
  45.     xmlns:draw="http://openoffice.org/2000/drawing"
  46.     xmlns:fo="http://www.w3.org/1999/XSL/Format"
  47.     xmlns:xlink="http://www.w3.org/1999/xlink"
  48.     xmlns:number="http://openoffice.org/2000/datastyle"
  49.     xmlns:svg="http://www.w3.org/2000/svg"
  50.     xmlns:chart="http://openoffice.org/2000/chart"
  51.     xmlns:dr3d="http://openoffice.org/2000/dr3d"
  52.     xmlns:math="http://www.w3.org/1998/Math/MathML"
  53.     xmlns:form="http://openoffice.org/2000/form"
  54.     xmlns:script="http://openoffice.org/2000/script"
  55.     xmlns:dc="http://purl.org/dc/elements/1.1/"
  56.     xmlns:meta="http://openoffice.org/2000/meta"
  57.     xmlns:config="http://openoffice.org/2001/config"
  58.     xmlns:help="http://openoffice.org/2000/help"
  59.     xmlns:xt="http://www.jclark.com/xt"
  60.     xmlns:common="http://exslt.org/common"
  61.     xmlns:xalan="http://xml.apache.org/xalan"
  62.     exclude-result-prefixes="office style text table draw fo xlink number svg chart dr3d math form script dc meta config help xt common xalan">
  63.  
  64.  
  65.     <!-- *********************************** -->
  66.     <!-- *** write repeating table cells *** -->
  67.     <!-- *********************************** -->
  68.  
  69.  
  70.     <!-- matching cells to give out -> covered table cells are not written out -->
  71.     <xsl:template match="table:table-cell">
  72.         <xsl:param name="globalData" />
  73.         <!-- position of the current input cell to get the correct colum style (hidden are also counted)-->
  74.         <xsl:param name="allTableColumns" />
  75.         <xsl:param name="maxRowLength" />
  76.         <xsl:param name="tableDataType" />
  77.  
  78.  
  79.         <!-- The column position of the current cell has to be determined
  80.         to get the adequate column styles during later cell creation,
  81.         or hiding the cell when @table:visibility is not set to 'visible'.
  82.  
  83.         The position is archieved by adding up all table:number-columns-repeated of the preceding cells.
  84.             Step1: creating '$precedingCells/quantity/@table:number-columns-repeated').
  85.             Step2: sum(xxx:nodeset($precedingCells)/quantity) + 1        -->
  86.         <xsl:variable name="precedingCells">
  87.             <xsl:for-each select="preceding-sibling::*">
  88.                 <xsl:choose>
  89.                     <!-- maybe a parser is used, which reads the DTD files (e.g. Xerces),
  90.                         then '1' is the default for 'table:number-columns-repeated' -->
  91.                     <xsl:when test="not(@table:number-columns-repeated and @table:number-columns-repeated > 1)">
  92.                         <xsl:element name="quantity" namespace="">
  93.                             <xsl:text>1</xsl:text>
  94.                         </xsl:element>
  95.                     </xsl:when>
  96.                     <xsl:otherwise>
  97.                         <xsl:element name="quantity" namespace="">
  98.                             <xsl:value-of select="@table:number-columns-repeated" />
  99.                         </xsl:element>
  100.                     </xsl:otherwise>
  101.                 </xsl:choose>
  102.             </xsl:for-each>
  103.         </xsl:variable>
  104.  
  105.         <xsl:choose>
  106.             <xsl:when test="function-available('xt:node-set')">
  107.                 <xsl:call-template name="create-table-cell">
  108.                     <!-- position of the current input cell to get the correct colum style (hidden are also counted)-->
  109.                     <xsl:with-param name="allTableColumns"  select="$allTableColumns" />
  110.                     <xsl:with-param name="maxRowLength"     select="$maxRowLength" />
  111.                     <xsl:with-param name="columnPosition"   select="sum(xt:node-set($precedingCells)/*) + 1" />
  112.                     <xsl:with-param name="globalData"       select="$globalData" />
  113.                     <xsl:with-param name="tableDataType"    select="$tableDataType" />
  114.                 </xsl:call-template>
  115.             </xsl:when>
  116.             <xsl:when test="function-available('common:nodeset')">
  117.                 <xsl:call-template name="create-table-cell">
  118.                     <!-- position of the current input cell to get the correct colum style (hidden are also counted)-->
  119.                     <xsl:with-param name="allTableColumns"  select="$allTableColumns" />
  120.                     <xsl:with-param name="maxRowLength"     select="$maxRowLength" />
  121.                     <xsl:with-param name="columnPosition"   select="sum(common:nodeset($precedingCells)/*) + 1" />
  122.                     <xsl:with-param name="globalData"       select="$globalData" />
  123.                     <xsl:with-param name="tableDataType"    select="$tableDataType" />
  124.                 </xsl:call-template>
  125.             </xsl:when>
  126.             <xsl:when test="function-available('xalan:nodeset')">
  127.                 <xsl:call-template name="create-table-cell">
  128.                     <!-- position of the current input cell to get the correct colum style (hidden are also counted)-->
  129.                     <xsl:with-param name="allTableColumns"  select="$allTableColumns" />
  130.                     <xsl:with-param name="maxRowLength"     select="$maxRowLength" />
  131.                     <xsl:with-param name="columnPosition"   select="sum(xalan:nodeset($precedingCells)/*) + 1" />
  132.                     <xsl:with-param name="globalData"       select="$globalData" />
  133.                     <xsl:with-param name="tableDataType"    select="$tableDataType" />
  134.                 </xsl:call-template>
  135.             </xsl:when>
  136.             <xsl:otherwise>
  137.                 <xsl:message terminate="yes">ERROR: Function not found: nodeset</xsl:message>
  138.             </xsl:otherwise>
  139.         </xsl:choose>
  140.     </xsl:template>
  141.  
  142.  
  143.     <!-- current node is a table:table-cell -->
  144.     <xsl:template name="create-table-cell">
  145.         <!-- position of the current input cell to get the correct colum style (hidden are also counted)-->
  146.         <xsl:param name="allTableColumns" />
  147.         <xsl:param name="globalData" />
  148.         <xsl:param name="maxRowLength" />
  149.         <xsl:param name="columnPosition" />
  150.         <xsl:param name="tableDataType" />
  151.  
  152.         <xsl:if test="$debugEnabled">
  153.             <xsl:message>
  154.                 <xsl:text>
  155.                     table:table-cell #</xsl:text>
  156.                 <xsl:value-of select="$columnPosition" />
  157.                 <xsl:text> has been entered with node value: </xsl:text>
  158.                 <xsl:value-of select="." />
  159.                 <xsl:text>
  160.                     table:number-columns-repeated: </xsl:text>
  161.                 <xsl:value-of select="@table:number-columns-repeated" />
  162.                 <xsl:text>
  163.                     maxRowLength: </xsl:text>
  164.                 <xsl:value-of select="$maxRowLength" />
  165.             </xsl:message>
  166.         </xsl:if>
  167.  
  168.         <!-- only non hidden column will be given out -->
  169.         <xsl:variable name="currentTableColumn" select="$allTableColumns/table:table-column[position() = $columnPosition]" />
  170.         <xsl:if test="$currentTableColumn[not(@table:visibility = 'collapse' or @table:visibility = 'filter')]">
  171.             <xsl:choose>
  172.                 <!-- if parser reads DTD the default is set to '1' -->
  173.                 <xsl:when test="@table:number-columns-repeated > 1">
  174.                     <!-- writes multiple entries of a cell -->
  175.                     <xsl:call-template name="repeat-write-cell">
  176.                         <xsl:with-param name="globalData"               select="$globalData" />
  177.                         <xsl:with-param name="allTableColumns"          select="$allTableColumns" />
  178.                         <xsl:with-param name="columnPosition"           select="$columnPosition" />
  179.                         <xsl:with-param name="currentTableColumn"       select="$currentTableColumn" />
  180.                         <xsl:with-param name="maxRowLength"             select="$maxRowLength" />
  181.                         <xsl:with-param name="numberColumnsRepeated"    select="@table:number-columns-repeated" />
  182.                         <xsl:with-param name="tableDataType"            select="$tableDataType" />
  183.                     </xsl:call-template>
  184.                 </xsl:when>
  185.                 <xsl:otherwise>
  186.                     <!-- writes an entry of a cell -->
  187.                     <xsl:call-template name="write-cell">
  188.                         <xsl:with-param name="globalData"           select="$globalData" />
  189.                         <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
  190.                         <xsl:with-param name="columnPosition"       select="$columnPosition" />
  191.                         <xsl:with-param name="currentTableColumn"   select="$currentTableColumn" />
  192.                         <xsl:with-param name="maxRowLength"         select="$maxRowLength" />
  193.                         <xsl:with-param name="tableDataType"        select="$tableDataType" />
  194.                     </xsl:call-template>
  195.                 </xsl:otherwise>
  196.             </xsl:choose>
  197.         </xsl:if>
  198.     </xsl:template>
  199.  
  200.  
  201.     <xsl:template name="repeat-write-cell">
  202.         <xsl:param name="globalData" />
  203.         <xsl:param name="allTableColumns" />
  204.         <xsl:param name="columnPosition" />
  205.         <xsl:param name="currentTableColumn" />
  206.         <xsl:param name="maxRowLength" />
  207.         <xsl:param name="numberColumnsRepeated" />
  208.         <xsl:param name="tableDataType" />
  209.  
  210.         <xsl:choose>
  211.             <!-- This is the current workaround for the flood of cells, simulation background by repeating cell -->
  212.             <xsl:when test="$numberColumnsRepeated > 1 and $maxRowLength > $columnPosition">
  213.  
  214.                 <!-- writes an entry of a cell -->
  215.                 <xsl:call-template name="write-cell">
  216.                     <xsl:with-param name="globalData"           select="$globalData" />
  217.                     <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
  218.                     <xsl:with-param name="columnPosition"       select="$columnPosition" />
  219.                     <xsl:with-param name="currentTableColumn"   select="$currentTableColumn" />
  220.                     <xsl:with-param name="tableDataType"        select="$tableDataType" />
  221.                 </xsl:call-template>
  222.                 <!-- repeat calling this method until all elements written out -->
  223.                 <xsl:if test="$debugEnabled">
  224.                     <xsl:message>+++++++++ cell repetition +++++++++</xsl:message>
  225.                 </xsl:if>
  226.                 <xsl:call-template name="repeat-write-cell">
  227.                     <xsl:with-param name="globalData"               select="$globalData" />
  228.                     <xsl:with-param name="allTableColumns"          select="$allTableColumns" />
  229.                     <xsl:with-param name="columnPosition"           select="$columnPosition + 1" />
  230.                     <xsl:with-param name="currentTableColumn"       select="$allTableColumns/table:table-column[position() = ($columnPosition + 1)]" />
  231.                     <xsl:with-param name="maxRowLength"             select="$maxRowLength" />
  232.                     <xsl:with-param name="numberColumnsRepeated"    select="$numberColumnsRepeated - 1" />
  233.                     <xsl:with-param name="tableDataType"            select="$tableDataType" />
  234.                 </xsl:call-template>
  235.             </xsl:when>
  236.             <xsl:otherwise>
  237.                 <!-- This is the current workaround for the flood of cells, simulation background by repeating cell -->
  238.                 <!--      When the maxRowLength is reached a last entry of a cell is written -->
  239.                 <xsl:call-template name="write-cell">
  240.                     <xsl:with-param name="globalData"           select="$globalData" />
  241.                     <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
  242.                     <xsl:with-param name="columnPosition"       select="$columnPosition" />
  243.                     <xsl:with-param name="currentTableColumn"   select="$currentTableColumn" />
  244.                     <xsl:with-param name="tableDataType"        select="$tableDataType" />
  245.                 </xsl:call-template>
  246.             </xsl:otherwise>
  247.         </xsl:choose>
  248.     </xsl:template>
  249.  
  250.  
  251.     <xsl:template name="write-cell">
  252.         <xsl:param name="globalData" />
  253.         <xsl:param name="allTableColumns" />
  254.         <xsl:param name="columnPosition" />
  255.         <xsl:param name="currentTableColumn" />
  256.         <xsl:param name="tableDataType" />
  257.  
  258.         <!-- a non hidden column will be give out -->
  259.         <xsl:choose>
  260.             <xsl:when test="$currentTableColumn[not(@table:visibility = 'collapse' or @table:visibility = 'filter')]">
  261.                 <xsl:call-template name="create-table-cell-content">
  262.                     <xsl:with-param name="globalData"           select="$globalData" />
  263.                     <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
  264.                     <xsl:with-param name="columnPosition"       select="$columnPosition" />
  265.                     <xsl:with-param name="currentTableColumn"   select="$currentTableColumn" />
  266.                     <xsl:with-param name="tableDataType"        select="$tableDataType" />
  267.                 </xsl:call-template>
  268.             </xsl:when>
  269.             <!-- a hidden column -->
  270.             <xsl:otherwise>
  271.                 <xsl:if test="$debugEnabled">
  272.                     <xsl:message>table column is hidden!</xsl:message>
  273.                 </xsl:if>
  274.             </xsl:otherwise>
  275.         </xsl:choose>
  276.     </xsl:template>
  277. </xsl:stylesheet>
  278.